﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TeamNitro.Student
{
    public partial class Students_Change_CDS : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DBManager_Jowie db = (DBManager_Jowie)Session["Student"];
            List<DBManager_Jowie> dbJowie1 = DBManager_Jowie.CurrentCDSSubjects(db.AdminNumber);
            lblNoOfSub.Text = dbJowie1.Count.ToString();

            for (int i = 0; i < dbJowie1.Count(); i++)
            {
                rbtnDropSubjects.Items.Add(dbJowie1[i].CDSName);
            }

            List<DBManager_Jowie> dbJowie2 = DBManager_Jowie.GetCDSSubjects();
            for (int i = 0; i < dbJowie1.Count(); i++)
            {
                for (int j = 0; j < dbJowie2.Count(); j++)
                {
                    if (dbJowie1[i].CDSName == dbJowie2[j].CDSName)
                    {
                        dbJowie2.RemoveAt(j);
                        break;
                    }
                }
            }

            for (int i = 0; i < dbJowie2.Count; i++)
            {
                ddlAddSubjects.Items.Add(dbJowie2[i].CDSName);
            }
        }

        protected void btnChangeSubmit_Click1(object sender, EventArgs e)
        {
            DBManager_Jowie db = (DBManager_Jowie)Session["Student"];
            List<DBManager_Jowie> dbJowie1 = DBManager_Jowie.CurrentCDSSubjects(db.AdminNumber);
            List<DBManager_Jowie> dbJowie2 = DBManager_Jowie.GetCDSSubjects();

            DBManager_Jowie dbJowie = new DBManager_Jowie();
            dbJowie.AdminNumber = db.AdminNumber;

            for (int i = 0; i < dbJowie1.Count(); i++)
            {
                if (rbtnDropSubjects.SelectedValue == dbJowie1[i].CDSName)
                {
                    dbJowie.CDSCode = dbJowie1[i].CDSCode;
                    dbJowie.CDSName = dbJowie1[i].CDSName;
                    break;
                }
            }

            for (int i = 0; i < dbJowie2.Count(); i++)
            {
                if (ddlAddSubjects.SelectedValue == dbJowie2[i].CDSName)
                {
                    dbJowie.ChangeCDSCode = dbJowie2[i].CDSCode;
                    dbJowie.ChangeCDSName = dbJowie2[i].CDSName;
                    break;
                }
            }

            dbJowie.Comment = tbxComment.Text;
            DBManager_Jowie.ChangeCDSSubject(dbJowie);

            rbtnDropSubjects.Items.Clear();
            ddlAddSubjects.Items.Clear();
        }
    }
}